package com.ssyc.gsk_parents.fragment;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;

import com.ssyc.common.base.LazyBaseFragment;
import com.ssyc.common.utils.UiUtils;
import com.ssyc.gsk_parents.R;
import com.ssyc.gsk_parents.activity.ParentsBabyHomeWorkActivity;
import com.ssyc.gsk_parents.activity.ParentsEvaluateTeacherActivity;
import com.ssyc.gsk_parents.activity.ParentsLeaveListActivity;
import com.ssyc.gsk_parents.activity.ParentsLessonTimeRecordActivity;
import com.ssyc.gsk_parents.activity.ParentsLiveListActivity;
import com.ssyc.gsk_parents.activity.ParentsRedPackageListActivity;
import com.ssyc.gsk_parents.activity.ParentsScoreInquiryActivity;
import com.ssyc.gsk_parents.adapter.HomeGvAdapter;
import com.ssyc.gsk_parents.bean.HomeInfo;

import java.util.ArrayList;
import java.util.List;

/**
 * 家长端主页Fragment
 * Created by Administrator on 2018/6/12 0012.
 */

public class ParentHomeFragment extends LazyBaseFragment implements AdapterView.OnItemClickListener {


    public static final String TAG = ParentHomeFragment.class.getName();


    //单体模式
    private static class LazyHolder {
        private static final ParentHomeFragment INSTANCE = new ParentHomeFragment();
    }

    public static final ParentHomeFragment newInstance() {
        return LazyHolder.INSTANCE;
    }

    //展示选项的GridView
    private GridView mGv;

    //首页的展示的条目的数据集合
    private List<HomeInfo> homeInfos;

    //适配器对象
    private HomeGvAdapter adapter;

    //首页的栏目的所有图片
    private int[] itemResId = {R.drawable.parents_jxmb, R.drawable.parents_ksjl, R.drawable.parents_bbzy, R.drawable.parents_cjcx, R.drawable.parents_zxqj,
            R.drawable.parents_wdhb, R.drawable.parents_pjls, R.drawable.parents_stzb};

    //首页的栏目名称
//    private String[] itemNames = {"教学目标", "课时记录", "宝贝练习", "成绩查询", "在线请假", "我的红包", "评价老师", "收听直播"};
    private String[] itemNames = {"课时记录", "课堂练习", "成绩查询", "在线请假", "我的红包", "评价老师", "收听直播"};

    @Override
    public void lazyInit(View view, Bundle savedInstanceState) {

    }

    @Override
    protected int getLayoutId() {
        return R.layout.parent_fragment_home;
    }

    @Override
    protected boolean isNeedShowTitle() {
        return false;
    }

    @Override
    protected String setTitleText() {
        return null;
    }

    @Override
    protected void init(View view, Bundle savedInstanceState) {
        super.init(view, savedInstanceState);

        showContent();

        //初始化视图
        initView(view);

        //初始化数据
        initData();

        //初始化列表
        initGv();

    }


    /**
     * 初始化视图
     */
    private void initView(View view) {
        mGv = view.findViewById(R.id.gv);
    }

    /**
     * 初始化数据
     */
    private void initData() {
        homeInfos = new ArrayList<>();
        for (int i = 0; i < itemNames.length; i++) {
            HomeInfo info = new HomeInfo();
            info.resId = itemResId[i];
            info.name = itemNames[i];
            homeInfos.add(info);
        }
    }

    /**
     * 初始化列表的方法
     */
    private void initGv() {
        adapter = new HomeGvAdapter(getContext(), homeInfos, R.layout.parent_gv_home);
        mGv.setAdapter(adapter);
        mGv.setOnItemClickListener(this);
    }

    /**
     * 列表的条目点击事件
     *
     * @param adapterView
     * @param view
     * @param pos
     * @param l
     */
    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int pos, long l) {
//        if (pos == 0) {
//            //教学目标
////            UiUtils.startActivity(getContext(), ParentsTeachingTargetActivity.class);
//            //开发中提示框
//            AlertDialogUtil.showAlertDialog(getActivity(), "程序GG正在努力开发中", new AlertDialogUtil.onClickListener() {
//                @Override
//                public void onClickOk() {
//                    CustomDialogManager.dissmiss();
//                }
//            });
//        } else
        if (pos == 0) {
            //课时记录
            UiUtils.startActivity(getContext(), ParentsLessonTimeRecordActivity.class);
        } else if (pos == 1) {
            //宝贝练习
            UiUtils.startActivity(getContext(), ParentsBabyHomeWorkActivity.class);
        } else if (pos == 2) {
            //成绩查询
            UiUtils.startActivity(getContext(), ParentsScoreInquiryActivity.class);
        } else if (pos == 3) {
            //在线请假
            UiUtils.startActivity(getContext(), ParentsLeaveListActivity.class);
        } else if (pos == 4) {
            //我的红包
            UiUtils.startActivity(getContext(), ParentsRedPackageListActivity.class);
        } else if (pos == 5) {
            //评价老师
            UiUtils.startActivity(getContext(), ParentsEvaluateTeacherActivity.class);
        } else if (pos == 6) {
            //收听直播
            UiUtils.startActivity(getContext(), ParentsLiveListActivity.class);
        }
    }
}
